<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'head.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
   <script type="text/javascript" src="js/jquery.js"></script>
   <script type="text/javascript" src="js/OlineUsers.js"></script>
   <script type="text/javascript">
    <!--
    var id=1;
    var userId;
       function getUsers(){
   //获取文本框的内容
   //document.getElementById("userName");是dom方式
    //Jquery方式，参数加上#可以找到id的属性的一个节点
   // var jqueryOb=$("#userName");
    //获取节点的值
    //var userName=jqueryOb.val();
   //          alert(userName);
    //将得到的数据发送到服务器端的servlet中
    //用jquery的XMLHttpRequest对象get方法封装
  //  $.get("AJAXServer?name="+userName,null,callBack);
	
    $.ajax( {
           type:"POST",
           url:"onlineUsers.action",
           dataType:"xml",
           success:callBack
    }  );
}
function callBack(data){
    
    //得到Jquery对象
   // var jqueryObj=$(data);
     //到message节点
   // var message=jqueryObj.find("user");
      //获取文本内容
    $(data).find('user').each(
    	function() {
    	 var id = $(this).find("id").text();
       var name = $(this).find("name").text();
       
       var f=true;
       var te=$("ul").children();
       while(te.length !=0){
          if(te.attr("id")==name){
            f=false;
            break ;
           }else{
            // $("#users").append("<li id="+name+">" + name + "</li>");
           }
          te=te.next();
       }
     
       if(f){
         $("#users").append("<li id='"+name+"'><a href='chartroom/content.jsp?reciverId="+id+"' onclick='setUp(\""+id+"\")' target='mainFrame'>" + name + "</a></li>");
       }
  
    });
    
}

   function  setUp(peerId){
   
      $.ajax( {
           type: "POST",
           url: "setUp.action",
           data: "reciverId="+peerId,
      });
   }
   function getUserId(id){
      userId=id;
      alert(userId);
   }
window.setInterval(getUsers,1000);
    //-->
   </script>
  </head>
  
  <body>
   <div>
   
     <table>
       <tbody>
         <tr>
           <td >在线用户</td>
         </tr>
           <tr>
           <td>
             <ul id="users">
              
             </ul>
           </td>
         </tr>
   
       </tbody>
     </table>
   </div>
   <a t>
  </body>
</html>
